package com.webserver.controllers;

import com.webserver.http.HttpRequest;
import com.webserver.http.HttpResponse;
import qrcode.QRCodeUtil;

import java.io.OutputStream;

/**
 * 工具业务
 * 例如生成二维码，验证码等
 */
public class ToolsController {
    public void createQRCode(HttpRequest request, HttpResponse response){
        String content = request.getParameter("content");
        try {
            OutputStream out = response.getOutStream();
            QRCodeUtil.encode(content,out);
            response.setContentType("image/jpeg");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) throws Exception {
        QRCodeUtil.encode("阳光明媚吗王桑？","./qrcode.jpg");
        QRCodeUtil.encode("http://www.jd.com","./webapps/myweb/jd.png","./qrcode.jpg",true);

        String message =QRCodeUtil.decode("./qrcode.jpg");
        System.out.println(message);
        System.out.println("二维码生成完毕");
    }
}
